package com.dg.river.core.view;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
import android.util.AttributeSet;

/**
 * Created by hy on 2018/10/29
 * Description : 重写NestedScrollView 实现滑动监听
 */
public class NestedScrollViewForScroll extends NestedScrollView {

    private ScrollViewListener scrollViewListener = null;

    public NestedScrollViewForScroll(@NonNull Context context) {
        super(context);
    }

    public NestedScrollViewForScroll(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public NestedScrollViewForScroll(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setScrollViewListener(ScrollViewListener scrollViewListener) {
        this.scrollViewListener = scrollViewListener;
    }

    @Override
    protected void onScrollChanged(int x, int y, int oldx, int oldy) {
        super.onScrollChanged(x, y, oldx, oldy);
        if (scrollViewListener != null) {
            scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
        }
    }

    public interface ScrollViewListener {
        void onScrollChanged(NestedScrollView scrollView, int x, int y, int oldx, int oldy);
    }
}
